package com.trailer.base.utils

import android.content.Context
import android.widget.Toast
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction

/**
 * Created by xianguangjin on 16/7/13.
 *
 *
 * 我的GitHub: https://github.com/home
 *
 *
 * 加油,做一个真的汉子
 */
object Toasts {
    private var toast: Toast? = null

    fun toast(context: Context?, message: CharSequence?, time: Int = Toast.LENGTH_SHORT) {
        toast = Toast.makeText(context, message, time)
        toast?.show()
    }

    fun toast(context: Context?, ResId: Int, time: Int = Toast.LENGTH_SHORT) {
        toast(context, context?.getString(ResId), time)
    }

    fun message(context: Context?, message: CharSequence?, title: CharSequence? = "温馨提示", positiveBtnName: CharSequence? = "确定", negativeBtnName: CharSequence? = "取消", positiveAction: QMUIDialogAction.ActionListener? = null, negativeAction: QMUIDialogAction.ActionListener? = null, negativeEnable: Boolean = false): QMUIDialog? {
        val messageDialogBuilder = QMUIDialog.MessageDialogBuilder(context)
                .setTitle(title.toString())
                .setMessage(message)
                .setCanceledOnTouchOutside(false);

        if (negativeEnable) {
            if (negativeAction == null) {
                messageDialogBuilder.addAction(0, negativeBtnName) { dialog, _ -> dialog.dismiss() }
            } else {
                messageDialogBuilder.addAction(0, negativeBtnName, negativeAction)
            }
        }

        if (positiveAction == null) {
            messageDialogBuilder.addAction(0, positiveBtnName) { dialog, _ -> dialog.dismiss() }
        } else {
            messageDialogBuilder.addAction(0, positiveBtnName, positiveAction)
        }

        return messageDialogBuilder
                .show()
    }


}


